package com.xinqi.modules.sys.textbook.enums;

import java.util.function.Supplier;

import static com.xinqi.common.base.error.CommonErrors.BAD_REQUEST;

/**
 * 云课本限制处理枚举
 *
 * @author linkai
 * @date 2023/5/2
 */
public enum TextbookLimitEnum {
    文件夹深度(3, "课本目录深度已超过最大限制"),
    ;

    private final long limitNum;
    private final String error;

    TextbookLimitEnum(long limitNum, String error) {
        this.limitNum = limitNum;
        this.error = error;
    }

    public void check(long num) {
        BAD_REQUEST.check(validate(num), error);
    }

    public void check(Supplier<Integer> s) {
        BAD_REQUEST.check(validate(s.get()), error);
    }

    public void check(int num, String error) {
        BAD_REQUEST.check(validate(num), error);
    }

    public boolean validate(long num) {
        return num <= limitNum;
    }
}
